tr: add codspeed benchmark#12189
Conversation
|
GNU testsuite comparison: |
|
|
||
| `tr` performance is critical for large data processing pipelines. The implementation uses lookup tables for O(1) character operations. | ||
|
|
||
| ## CodSpeed (CI) |
| /// Exercises the AVX2 ASCII-range fast path on x86_64 hosts that | ||
| /// support it, and the scalar range fallback on other targets. | ||
| #[cfg(unix)] | ||
| #[divan::bench(args = [1, 16, 64])] |
There was a problem hiding this comment.
Please test with only one value
There was a problem hiding this comment.
Done in 190a973 — collapsed to a single 16 MB size (SIZE_MB const) across all four benches.
Adds a divan-based benchmark suite under src/uu/tr/benches/ that codspeed can build and run, and registers uu_tr in the benchmarks workflow matrix. Each bench redirects fd 0 to a prepared file and fd 1 to /dev/null around uumain since tr only reads stdin. Covers the AVX2 ASCII-range fast path, single-char replace, multi-char table translation, and ASCII range delete, at 1/16/64 MB.
f99615e to
190a973
Compare
| //! so the translated output does not flood the harness's terminal. | ||
| //! Both fds are restored after each iteration. | ||
|
|
||
| #[cfg(unix)] |
There was a problem hiding this comment.
why all these unix cfg ?
There was a problem hiding this comment.
Good point. I kept the benchmark Unix-gated because it redirects stdin/stdout with rustix fd helpers and /dev/null, but grouped the benchmark code under one cfg(unix) module to make that clearer.
|
Is this OK to merge? |
Merging this PR will improve performance by 3.81%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
What
Adds a divan-based benchmark suite at
src/uu/tr/benches/tr_bench.rs, registered in.github/workflows/benchmarks.ymlso CodSpeed tracks it on every PR.tronly reads stdin, so each bench redirects fd 0 to a prepared file (and fd 1 to/dev/null) arounduumain, mirroring the existingsrc/uu/tee/benches/tee_bench.rspattern withrustix.The suite covers four cases at 1 / 16 / 64 MB inputs:
tr_ascii_range_lower_to_upper—tr a-z A-Z(range translation)tr_single_char_replace—tr a b(single-byte SIMD path)tr_multi_char_translate—tr aeiou AEIOU(table-lookup path)tr_delete_ascii_range—tr -d a-z(deletion path)Why
Requested by @sylvestre in #12118 to provide regression coverage for the
trtranslation paths and the upcoming AVX2 ASCII-range fast path landing in that PR.Local invocation
Notes
#[cfg(unix)]because the rustix stdin/stdout redirection is unix-only; on other targets the bench compiles to an emptydivan::main().benches/,Cargo.tomldev-deps, and the workflow matrix.